L.TVManager = L.Class.extend({
	includes: L.Mixin.Events,

	initialize: function(couplingOptions) {
		
		this._tvs = {};
		
		this._couplingOptions = couplingOptions;		
		this._couple(this._couplingOptions);
		
	},
	
	requestFollowingJoin: function( subjectVersionId, activityId ) {
		this.fire('followingJoinRequest',{
			subjectVersionId: subjectVersionId, 
			activityId: activityId
		});
	},
	
	requestGroupJoin: function(tvId, subjectVersionId, activityId, groupName, groupType) {
		this._tvs[tvId] = {
			subjectVersionId: subjectVersionId, 
			activityId: activityId, 
			groupName: groupName, 
			groupType: groupType
		};
		
		this.fire("groupJoinRequest",{
			tvId: tvId,
			subjectVersionId: subjectVersionId, 
			activityId: activityId, 
			groupName: groupName, 
			groupType: groupType
		});
	},
	
	requestRoomFocus: function(roomId, groupName, groupType) {
		this.fire("roomFocusRequest",{
			roomId: roomId, 
			groupName: groupName, 
			groupType: groupType
		});
	},
	
	getTV: function(tvId) {
		return this._tvs[tvId];
	},
	
	getTVs: function() {
		return this._tvs;
	},
	
	_couple: function(couplingOptions) {
		if ( couplingOptions && couplingOptions.enabled ) {
			couplingOptions.adapter.coupleObject(
				couplingOptions.carriedId, 
				this,
				{
					messageType: "EVENT",
					explicitMapping: ["requestGroupJoin", "requestRoomFocus", 'requestFollowingJoin']
				}
			);
		}
	}
	
});